package com.lishe.lishe.lishe.module.mall.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lishe.lishe.R;
import com.lishe.lishe.lishe.MyRecyclerView.RecyclerviewBaseAdapter;
import com.lishe.lishe.lishe.bean.AddressItem;

import java.util.List;

/**
 * Created by Bin
 * 促销信息弹窗 adapter
 */

public class GoodsAddressAdapter extends RecyclerviewBaseAdapter {

    private Context mContext;
    private List<AddressItem> mAddressList;

    public GoodsAddressAdapter(Context context, List<AddressItem> list) {
        this.mContext = context;
        this.mAddressList = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolderMy(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_goodsaddress, null);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolderMy(RecyclerView.ViewHolder holder0, final int position) {
        ViewHolder holder = (ViewHolder) holder0;
        holder.address.setText(mAddressList.get(position).getArea() + mAddressList.get(position).getAddr());
        if (mAddressList.get(position).isCheck()) {
            holder.address.setTextColor(mContext.getResources().getColor(R.color.color_ff4138));
            holder.locLogo.setBackgroundResource(R.mipmap.location);
            holder.select.setVisibility(View.VISIBLE);
        } else {
            holder.address.setTextColor(mContext.getResources().getColor(R.color.gray_6));
            holder.locLogo.setBackgroundResource(R.mipmap.location1);
            holder.select.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCountMy() {
        return mAddressList == null ? 0 : mAddressList.size();
    }

    @Override
    public int getItemViewTypeMy(int position) {
        return 0;
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        View select;
        View locLogo;
        TextView address;

        public ViewHolder(View itemView) {
            super(itemView);
            select = itemView.findViewById(R.id.select);
            locLogo = itemView.findViewById(R.id.loc_logo);
            address = itemView.findViewById(R.id.address);
        }
    }
}
